import {FC, Key, useCallback, useEffect, useRef, useState} from "react";
import {Space, Button, message} from "antd";
import {useFormEffects} from '@formily/react';
import {onFormMount} from '@formily/core';
import {DynamicObjectAny} from "@ey-utils/utils/typings";
import {Input as AntdInput} from 'antd';

interface InputSearchAddProps<V = any> {
    onChange: (value: V, record?: DynamicObjectAny | DynamicObjectAny[]) => void;
    editable?: boolean;
    _value?: string;
    onClick?: any;
}

const InputSearchAdd: FC<InputSearchAddProps>
    = ({
           onChange,
           editable,
           _value,
           onClick,
           ...restProps
       }) => {
    const formRef = useRef<any>();
    const [value, setValue] = useState('');
    useFormEffects(() => {
        onFormMount((form) => {
            formRef.current = form;
        });
    });

    const add = () => {
        onClick && onClick(value)
    }

    const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
        const {value: inputValue} = e.target;
        setValue(inputValue)
    }
    return (
        <>
            <Space>
                <AntdInput value={value} onChange={onInputChange}/>
                <Button type="primary" onClick={add}>
                    新增
                </Button>
            </Space>


        </>
    );
};

export default InputSearchAdd;
